<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib  prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib  prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="redis" uri="http://www.shopjsp.com/redisTag/functions" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="defaultImg" value="${redis:getSysConfig('website_default_img')}"/>
<c:set var="srcPath" value="${redis:getSysConfig('sysFileVisitRoot_back')}"/>
<c:set var="basePath" value="${redis:getSysConfig('base_path_back')}"/>
<c:set var="uploadPath" value="${redis:getSysConfig('uploadFileVisitRoot')}"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>分配权限信息</title>
	<jsp:include page="../../util/import.jsp"/>
	<%--bootstrap_tree css文档--%>
	<link rel="stylesheet" type="text/css" href="${srcPath}/3thParty/bootstrap_tree/css/bootstrap-treeview.css"/>
	<%--bootstrap_tree js文档--%>
	<script type="text/javascript" src="${srcPath}/3thParty/bootstrap_tree/js/bootstrap-treeview.js"></script>

	<script type="text/javascript">

        $(function () {
            /**参数1：加载树节点的url，参数2：当前业务下主键名称约定，参数3：管理树本身的操作类型名称约定**/
            initTree('${basePath}/back/purview/getNodes.sjson','purviewId','manager');

            var $tt= $("#tt").bootstrapTable({
                url: '${basePath}/back/purview/listIsLeafPurviewByParentId.sjson ',        	/**请求后台的URL（*）**/
                method: 'post',                       	/**请求方式（*）**/
                contentType: "application/x-www-form-urlencoded",
                dataType: 'json',
                toolbar: '#toolbar',               	    /**工具按钮用哪个容器**/
                striped: true,                      	/**是否显示行间隔色**/
                cache: false,                       	/**是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）**/
                pagination: true,                   	/**是否显示分页（*）**/
                sortable: false,                    	/**是否启用排序**/
                sortOrder: 'asc',                   	/**排序方式**/
                queryParamsType: '',
                sidePagination: 'server',           	/**分页方式：client客户端分页，server服务端分页（*）**/
                pageNumber: 1,
                pageSize:10,							/**初始化加载第一页，默认第一页**/
                pageList: [5,10, 25, 50],        	    /**可供选择的每页的行数（*）**/
                search: false,                       	/**是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大**/
                strictSearch: true,
                showColumns: true,                  	/**是否显示所有的列**/
                showRefresh: true,                  	/**是否显示刷新按钮**/
                minimumCountColumns: 2,             	/**最少允许的列数**/
                clickToSelect: true,                	/**是否启用点击选中行**/
                uniqueId: 'purviewId',                  /**每一行的唯一标识，一般为主键列**/
                singleSelect  : true,                   /** 单选checkbox**/
                showToggle:false,                    	/**是否显示详细视图和列表视图的切换按钮**/
                cardView: false,                    	/**是否显示详细视图**/
                detailView: false,                  	/**是否显示父子表**/
                columns: [
                    {checkbox: true},
                    {field: 'Number', title: '编号',align: 'center',valign: 'middle',width:'50px',
                        formatter: function (value, row, index) {
                            var page = $tt.bootstrapTable("getPage");
                            return page.pageSize * (page.pageNumber - 1) + index + 1;
                        }
                    },
					{field: 'purviewName',title: '当前菜单权限',align: 'center',valign: 'middle'},
                    {field: 'levelCode',title: '菜单权限级别',align: 'center',valign: 'middle',
                        formatter:function(value,row,index){
                            if(value==1){
                                return "<font class='color_001'>一级菜单权限</font>";
                            }else if(value==2){
                                return "<font class='color_001'>二级菜单权限</font>";
                            }else {
                                return "<font class='color_001'>三级菜单权限</font>";
                            }
                        }
                    },
                    {field: 'isLeaf',title: '节点类型',align: 'center',valign: 'middle',
                        formatter:function(value,row,index){
                            if(value==1){
                                return "<font class='color_001'>叶节点</font>";
                            }else {
                                return "<font class='color_002'>分支节点</font>";
                            }
                        }
                    },
                    {field: 'sortCode',title: '排序号',align: 'center',valign: 'middle'},
                    {field: 'isAssginPurview',title: '菜单权限分配',align: 'center',valign: 'middle',
                        formatter:function(value,row,index){
                            if(value==null||value==undefined){
                                return "<font class='color_002'>尚未分配</font>";
                            }else{
                                return "<font class='color_001'>已分配</font>";
							}
                        }
                    },
                    {field: 'functions',title: '功能权限分配',align: 'center',valign: 'middle',
                        formatter:function(value,row,index){
                            if(value==null||value==undefined){
                                return "<span class='label label-danger'>尚未分配</span>";
                            }else{
                                var funNames="";
                                var functions_array=value.split(",");
                                for(var i=0;i<functions_array.length;i++){
                                    var functions_subarray=functions_array[i].split("_");
                                    funNames+= "<span class='label label-success'>" + functions_subarray[1] + "</span>" +"&nbsp;&nbsp;";
                                }
                                return funNames;
							}
                        }
                    },
                    {field: 'parentPurviewName',title: '上级菜单权限',align: 'center',valign: 'middle'},
                    {field: 'actorName',title: '关联角色',align: 'center',valign: 'middle',
                        formatter:function(value,row,index){
                            return '${actorName}';
                        }
                    }
                ],
                queryParams: function (params) {
                    /**特别说明，返回的参数的值为空，则当前参数不会发送到服务器端,这种指定请求参数的方式和datatables控价类似**/
                    params.purviewName = $("#q_purviewName").val();
                    params.parentId = $("#q_purviewId").val();
                    params.actorId =${actorId};
                    params.currentPage = params.pageNumber;
                    return params;
                }
            });

        });


        /**
         * 移除菜单权限
         */
        function deleteInfo(){
            /**获取选中行的id**/
            var selectedRow= $("#tt").bootstrapTable('getSelections');
            if(selectedRow.length==1){
                var id=selectedRow[0].purviewId;
                showConfirm("你确定要删除吗?", function() {
                    $.ajax({
                        type: "POST",
                        dataType: "JSON",
                        url: "${basePath}/back/actorPurview/deleteActorPurview.sjson",
                        data: {actorId:${actorId},purviewId:id},
                        success: function(data){
                            if(data.success==true){
								$("#tt").bootstrapTable('refresh');
                            }else {
                                showMsg("菜单权限移除失败！");
                            }
                        }
                    });
                });
            }else{
                showMsg("请选择一行记录！");
            }
        }

        /**
		 * 分配菜单权限
         */
        function assginMenuPurviewInfo(){
            var selectedRow= $("#tt").bootstrapTable('getSelections');
            if(selectedRow.length==1){
                var isAssginPurview=selectedRow[0].isAssginPurview;
                if(isAssginPurview==null||isAssginPurview==undefined){
                    var id=selectedRow[0].purviewId;
                    $.ajax({
                        type: "POST",
                        dataType: "JSON",
                        url: "${basePath}/back/actorPurview/saveActorPurview.sjson",
                        data: {actorId:${actorId},purviewId:id},
                        success: function(data){
                            if(data.success==true){
                                showMsg("菜单权限分配成功！");
                                $("#tt").bootstrapTable('refresh');
                            }else {
                                showMsg("菜单权限分配失败！");
                            }
                        }
                    });
                }else{
                    showMsg("该菜单权限已经分配，请不要重复分配！");
                }
            }else{
                showMsg("请选择一行记录！");
            }
		}

	</script>
</head>
<body>
<div class="panel-body" id="customer-main-panel">

	<div style="width: 13%;margin:5px;float:left;" id="tv"></div>

	<!-- 渲染的table -->
	<div style="float:left;margin-left: 15px;width: 85%;">
		<!-- 查询条件 -->
		<div class="panel panel-default">
			<div class="panel-heading">分配权限查询</div>
			<div class="panel-body">
				<form id="qform" class="form-horizontal">
					<div class="form-group" style="margin-top:15px">
						<div class="col-sm-3" >
							<div class="input-group input-group-sm">
								<span class="input-group-addon">权限名称</span>
								<input type="text" class="form-control" id="q_purviewName" name="purviewName" placeholder="请输入权限名称"/>
							</div>
						</div>
						<div>
							<!-- 设置当前分类列表的父分类Id -->
							<input type="hidden" id="q_purviewId" name="purviewId"/>
							<input type="hidden" id="q_isLeaf" name="isLeaf"/>
						</div>

						<div class="col-sm-3">
							<button type="button" id="btn_query" class="btn btn-primary">查询</button>&nbsp;&nbsp;
							<button type="reset" class="btn btn-success" id="resetBtn">重置</button>
						</div>
					</div>
				</form>
			</div>
		</div>

		<!-- 工具栏 -->
		<div id="toolbar" class="btn-group">
			<button id="btn_remove_add" type="button" class="btn btn-default" data-toggle="modal" onclick="assginMenuPurviewInfo()">
				<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>分配菜单权限
			</button>
			<button id="btn_remove_function" type="button" class="btn btn-default" data-toggle="modal" onclick="deleteInfo()">
				<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>移除菜单权限
			</button>
			<button id="btn_assgin_function" type="button" class="btn btn-default" data-toggle="modal" data-target="#addOrEditModal" onclick="editPurviewAndFunction()">
				<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>分配功能权限
			</button>
			<button id="btn_backward" type="button" class="btn btn-default"  onclick="window.location.href=document.referrer;">
				<span class="glyphicon glyphicon-backward" aria-hidden="true"></span>返回角色列表
			</button>
		</div>
		<table id="tt"></table>

	</div>


	<!-- 功能权限页面 -->
	<jsp:include page="addActorPurview.jsp"/>



</div>
</body>
</html>
